package com.fdb.efp.cus.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.cus.service.dao.GreyBlackListDao;
import com.fdb.efp.cus.service.domain.GreyBlackList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.cus.service.facade.GreyBlackListService;
import com.fdb.efp.cus.service.vo.GreyBlackListVO;
/**
 * <p>ServiceImpl: 黑灰名单表（反洗钱名单表）<p>
 * @author ligm
 * @date 2019-05-22
 */
@Service("greyBlackListService")
public class GreyBlackListServiceImpl implements GreyBlackListService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(GreyBlackListServiceImpl.class);

	@Autowired
	private GreyBlackListDao greyBlackListDao;
	
	/**
	 * 新增操作
	 */
	public int insertGreyBlackList(GreyBlackListVO inGreyBlackListVo) {
		logger.debug("当前新增数据为:"+ inGreyBlackListVo.toString());
		int num = 0;
		try {
			GreyBlackList greyBlackList = new GreyBlackList();
			beanCopy(inGreyBlackListVo, greyBlackList);
			num = greyBlackListDao.insertGreyBlackList(greyBlackList);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(GreyBlackListVO inGreyBlackListVo) {
		logger.debug("当前删除数据条件为:"+ inGreyBlackListVo);
		int num = 0;
		try {
			GreyBlackList greyBlackList = new GreyBlackList();
			beanCopy(inGreyBlackListVo, greyBlackList);
			num = greyBlackListDao.deleteByPk(greyBlackList);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inGreyBlackListVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(GreyBlackListVO inGreyBlackListVo) {
		logger.debug("当前修改数据为:"+ inGreyBlackListVo.toString());
		int num = 0;
		try {
			GreyBlackList greyBlackList = new GreyBlackList();
			beanCopy(inGreyBlackListVo, greyBlackList);
			num = greyBlackListDao.updateByPk(greyBlackList);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inGreyBlackListVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public GreyBlackListVO queryByPk(GreyBlackListVO inGreyBlackListVo) {
		
		logger.debug("当前查询参数信息为:"+ inGreyBlackListVo);
		try {
			GreyBlackList queryGreyBlackList = new GreyBlackList();
			beanCopy(inGreyBlackListVo, queryGreyBlackList);
			GreyBlackList queryRslGreyBlackList = greyBlackListDao.queryByPk(queryGreyBlackList);
			if (Objects.nonNull(queryRslGreyBlackList)) {
				GreyBlackListVO outGreyBlackListVo = beanCopy(queryRslGreyBlackList, new GreyBlackListVO());
				logger.debug("当前查询结果为:"+ outGreyBlackListVo.toString());
				return outGreyBlackListVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<GreyBlackListVO> queryAllOwner(GreyBlackListVO greyBlackListVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<GreyBlackListVO> list = null;
		try {
			List<GreyBlackList> greyBlackLists = greyBlackListDao.queryAllOwnerByPage(greyBlackListVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ greyBlackLists.size());
			pageSet(greyBlackLists, greyBlackListVo);
			list = (List<GreyBlackListVO>) beansCopy(greyBlackLists, GreyBlackListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<GreyBlackListVO> queryAllCurrOrg(GreyBlackListVO greyBlackListVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<GreyBlackList> greyBlackLists = greyBlackListDao.queryAllCurrOrgByPage(greyBlackListVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+greyBlackLists.size());
		List<GreyBlackListVO> list = null;
		try {
			pageSet(greyBlackLists, greyBlackListVo);
			list = (List<GreyBlackListVO>) beansCopy(greyBlackLists, GreyBlackListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<GreyBlackListVO> queryAllCurrDownOrg(GreyBlackListVO greyBlackListVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<GreyBlackList> greyBlackLists = greyBlackListDao.queryAllCurrDownOrgByPage(greyBlackListVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ greyBlackLists.size());
		List<GreyBlackListVO> list = null;
		try {
			pageSet(greyBlackLists, greyBlackListVo);
			list = (List<GreyBlackListVO>) beansCopy(greyBlackLists, GreyBlackListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public int countGreyBlkLtByCust(GreyBlackListVO greyBlackListVo) {
		logger.debug("当前查询参数为："+ JSON.toJSONString(greyBlackListVo));
		int num = 0;
		try {
			GreyBlackList greyBlackList = new GreyBlackList();
			beanCopy(greyBlackListVo, greyBlackList);
			num = greyBlackListDao.countGreyBlkLtByCust(greyBlackList);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据证件类型、证件号码得到的结果总数为："+ num);
		return num;
	}
	
}
